<extend name="Public:main" />
<block name="title">银行卡</block>
<block name="body">
<body ng-app="myApp" ng-controller="Ctrl" ng-cloak>
    <div class="nav_top flex">
        <a  href="javascript:void(0)"  onclick="window.history.go(-1)">
            <i></i>
        </a>
        <div class="flex1">
            银行卡
        </div>
        <a  href="javascript:void(0)">
          
        </a>
    </div>
    <div style="height: 0.44rem;"></div>
    <p class="b_tip">
        <i></i>
        <span>务必保证收款账户姓名、账户等信息真实有效</span>
    </p>
    <div class="bank_list">
        <ul>
            <li class="flex" ng-repeat="li in bankList">
                <div>
                    <i></i>
                </div>
                <div class="flex1">
                    <label>
                        <span>
                            {{ li.realname }}
                        </span>
                        <span>
                            {{ li.bankname }}
                        </span>
                    </label>
                    <p>
                        {{ li.no }}
                    </p>
                </div>
                <div class="red" ng-if="li.isdefault == 1">
                    默认
                </div>
                <div ng-if="li.isdefault == 0">
                    <button ng-click="setDefault(li.id)">
                        设为默认
                    </button>
                    <button ng-click="del(li.id)">
                        删除
                    </button>
                </div>
            </li>
        </ul>
    </div>
    <div style="height: 0.45rem;"></div>
    <a style="position: fixed;bottom: 0;left: 5.6%;" class="login_btn" href="{:U('Member/addBankcard')}">
        添加银行卡
    </a>
</body>
    <block name="custom_js">
        <script>
            var app = getApp('myApp', []);
            app.controller('Ctrl', function ($scope, $http) {
                $http({
                    method:'POST',
                    data:{
                        "memberId" : $("input[name='memberId']").val(),
                        "nickname" : $("input[name='nickname']").val(),
                    },
                    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                    transformRequest: function(obj) {
                        var str = [];
                        for (var p in obj) {
                            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                        }
                        return str.join("&");
                    },
                    url: "/index.php/Home/Member/bankList"
                }).then(function successCallback(response) {
                    if(response.data.code==0){
                        $scope.bankList = response.data.data;
                    }else {
                        layer.msg(response.data.msg)
                    }
                }, function errorCallback(response) {
                    errorHandle(response);
                });

                //设置默认银行卡
                $scope.setDefault = function (id) {
                    $http({
                        method:'POST',
                        data:{
                            "id" : id,
                        },
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                        transformRequest: function(obj) {
                            var str = [];
                            for (var p in obj) {
                                str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                            }
                            return str.join("&");
                        },
                        url: "/index.php/Home/Member/setDefaultCard"
                    }).then(function successCallback(response) {
                        if(response.data.code==0){
                            layer.msg(response.data.data);
                            setTimeout(function () {
                                location.reload();
                            }, 1000);
                        }else {
                            layer.msg(response.data.msg)
                        }
                    }, function errorCallback(response) {
                        errorHandle(response);
                    });
                }

                //删除
                $scope.del = function (id) {
                    layer.confirm('确认删除？', {
                        btn: ['确认','取消'] //按钮
                    }, function(){
                        $http({
                            method:'POST',
                            data:{
                                "id" : id,
                            },
                            headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                            transformRequest: function(obj) {
                                var str = [];
                                for (var p in obj) {
                                    str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                                }
                                return str.join("&");
                            },
                            url: "/index.php/Home/Member/delBankCard"
                        }).then(function successCallback(response) {
                            if(response.data.code==0){
                                layer.msg(response.data.data);
                                setTimeout(function () {
                                    location.reload();
                                }, 1000);
                            }else {
                                layer.msg(response.data.msg)
                            }
                        }, function errorCallback(response) {
                            errorHandle(response);
                        });
                    }, function() {
                        layer.msg('已取消');
                    })
                }
            });
        </script>
    </block>
</block>